<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Element</title>
  <script>
    function test() {
      console.log(1);
    }
    window.onload = function () {
      var div = document.getElementsByTagName('div')[0];
      // console.log(div);
      console.log(div.id);
      console.log(div.title);
      console.log(div.className);
      // 访问不到
      // console.log(div['data-flag']);
      // 另一种方式
      console.log(div.getAttribute('data-flag'));
      div.id = 'one1'
      console.log(div.id);
      div.removeAttribute('title')
      console.log(div.title);
      console.log(div.onclick);

    }
  </script>
</head>

<body>
  <div id="one" class="two" title="hello" data-flag="testdata"
    style="width: 100px;height: 100px;background-color: aquamarine;" onclick="test()"></div>
</body>

</html>